import {ref} from 'vue'

import {listAllManageNode} from "@/api/manager/manageNode";
import {listAllCollectPassage} from "@/api/manager/collectPassage";
import {listAllCollectPoint} from "@/api/manager/collectPoint";
import {transformProperty} from '@/utils/json'
export let nodeId = ref(null)
export let passageCode = ref(null)
export let pointCode = ref(null)

export const passageOptions = ref([]);
export const nodeOptions = ref([]);
export const pointOptions = ref([]);


/** 查询通道列表 */
export function queryPassageByNodeId(nodeId) {
    //清空点位列表
    pointOptions.value =[];
    listAllCollectPassage({nodeId}).then(response => {
        if (response.code == 200) {
            passageOptions.value = transformProperty(response.data,{'passageCode': 'value', "passageName": 'label'});
        }

    });
}
export function queryPointBypassageCode(passageId) {
    //没有选通道不允许获取点位
    if(!passageId){
        pointOptions.value =[];
        return ;
    }
    listAllCollectPoint({passageId}).then(response => {
        if (response.code == 200) {
            pointOptions.value = transformProperty(response.data,{'pointCode': 'value', "pointName": 'label'});

        }

    });
}
/** 查询端列表 */
export function getNodeList(nodeId) {
    listAllManageNode({}).then(response => {
        if (response.code == 200) {
            nodeOptions.value = transformProperty(response.data,{'nodeId': 'value', "nodeName": 'label'});
        }

    });
}

export function queryNodeIdpassageCodePointId (){
    return {passageCode:passageCode.value,nodeId:nodeId.value,pointCode:pointCode.value}
}